package org.example.chatroom.common.advice;

import lombok.extern.slf4j.Slf4j;
import org.example.chatroom.common.exception.ChatroomException;
import org.example.chatroom.common.pojo.response.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LIUYANJIAO
 * Date: 2025-06-21
 * Time: 14:58
 */
@Slf4j
@ControllerAdvice
@ResponseBody
public class ExceptionAdvice {
    @ExceptionHandler(Exception.class)
    public Result exceptionAdvice(Exception e){
        log.error("发生异常 : e{}",e);
        return Result.fail(e.getMessage());
    }
    @ExceptionHandler(ChatroomException.class)
    public Result exceptionAdvice(ChatroomException e){
        log.error("发生异常 : e{}",e);
        return Result.fail(e.getErr());
    }
}
